/*
题目链接;https://leetcode.cn/problems/determine-the-minimum-sum-of-a-k-avoiding-array/description/?envType=daily-question&envId=2025-03-26
*/

//题解代码:
class Solution {
public:
    int minimumSum(int n, int k) {
        int l = k/2+1, r = min(k-1,n);
        if(k<3 || n<l) return (1+n)*n/2;
        int cnt = r-l+1;
        int ans = (1+n)*n/2 - (l+r)*cnt/2;
        r = max(k,n+1);
        ans += (r+r+cnt-1)*cnt/2;
        return ans;
    }
};
